////////////////////////////////////////////////////////////////////////////////
//
//  based on Adobe source
//
//  link:
//
//  http://opensource.adobe.com/svn/opensource/flex/sdk/tags/4.0.0.4021/frameworks/projects/flex4/src/mx/graphics/Parser.as
//
// enhancement by suspendmode@gmail.com
//
//
////////////////////////////////////////////////////////////////////////////////

package com.google.code.fxg.schema
{		
		
	////////////////////////////////////////////////////////////////////////////////
	//
	//  Helper class: ObjectElement
	//
	////////////////////////////////////////////////////////////////////////////////
	
	/**
	 *  @private
	 */
	public class ObjectElement
	{
		
		//-----------------------------------------------------------------------------
		//
		//  Class methods
		//
		//-----------------------------------------------------------------------------
		
		/**
		 *  @private
		 */
		private static function buildObject(value:*):Object
		{
			var result:Object;
			
			if (value is Array)
			{
				result = {};
				var n:int = value.length;
				for (var i:int = 0; i < n; i++)
				{
					var o:Object = value[i];
					for (var p:String in o)
					{
						result[p] = o[p];
					}
				}
			}
			else
			{
				result = value;
			}
			
			return result;
		}
		
		//-----------------------------------------------------------------------------
		//
		//  Constructor
		//
		//-----------------------------------------------------------------------------
		
		/**
		 *  Constructor.
		 */
		public function ObjectElement(name:String, type:Class,
									  attributes:*, elements:* = null,
									  defaultProperty:String = null,
									  defaultTypes:ObjectElementGroup = null)
		{
			this.name = name;
			this.type = type;
			this.attributes = buildObject(attributes);
			this.elements = buildObject(elements);
			this.defaultProperty = defaultProperty;         
			this.defaultTypes = defaultTypes;
		}
		
		//-----------------------------------------------------------------------------
		//
		//  Properties
		//
		//-----------------------------------------------------------------------------
		
		/**
		 *  @private
		 */
		public var name:String;
		
		/**
		 *  @private
		 */
		public var type:Class;
		
		/**
		 *  @private
		 */
		public var attributes:Object;
		
		/**
		 *  @private
		 */
		public var elements:Object;
		
		private var _defaultProperty:String = "mxmlContent";
		
		/**
		 *  @private
		 */
		public function get defaultProperty():String
		{
			return _defaultProperty;
		}
		
		/**
		 * @private
		 */
		public function set defaultProperty(value:String):void
		{
			_defaultProperty = value;
		}
		
		
		/**
		 *  @private
		 */
		public var defaultTypes:ObjectElementGroup;
	}
}